import { Application } from "egg";
import * as AutoIncrementFactory from "mongoose-sequence";
export interface StandardProps {
  id?: number;
  standard: string; // 规格名称
  is_delete: boolean; // 是否删除
}
function initStandardModel(app: Application) {
  const mongoose = app.mongoose;
  const Schema = mongoose.Schema;
  const AutoIncrement = AutoIncrementFactory(mongoose);
  const StandardScheme = new Schema<StandardProps>(
    {
      standard: { type: String, unique: true, required: true },
      is_delete: { type: Boolean, default: false },
    },
    {
      timestamps: true,
      toJSON: {
        transform(_doc, ret) {
          delete ret.__v;
        },
      },
    }
  );
  StandardScheme.plugin(AutoIncrement, {
    inc_field: "id",
    id: "Standard_counter",
  });
  return mongoose.model<StandardProps>("Standard", StandardScheme);
}

export default initStandardModel;
